package com.leonzx.base.controller.layim;
import com.leonzx.base.service.system.ChatBodyService;
import org.jim.common.packets.ChatBody;
import org.jim.server.command.handler.processor.chat.AbstractChatProcessor;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.tio.core.ChannelContext;

/**
 * 继承AbstractChatProcessor父类
 * 监听即时通讯发送的内容
 * @Author:李晓雷
 * @Description:
 * @Date: 18/07/20 16:09
 */
public class DefaultChatProcessor extends AbstractChatProcessor {
    Logger logger = LoggerFactory.getLogger(DefaultChatProcessor.class);
    private ChatBodyService chatBodyService;
    public DefaultChatProcessor(ChatBodyService chatBodyService){
        this.chatBodyService = chatBodyService;
    }

    /**
     * 监听即时通讯发送内容
     * @param chatBody
     * @param channelContext
     */
    @Override
    public void doHandler(ChatBody chatBody, ChannelContext channelContext) {
        //保存消息到数据库
        try {
            chatBodyService.save(chatBody);
        }catch (Exception e){
            logger.error("保存聊天内容失敗",e);
        }
    }
}
